export interface Item{
  pid:number
  name:string
  img:string
  short:string
  tel:string
}
export interface Tree{
  title:string
  children:Item[]
}

export function toTree(arr:Item[]):Tree[]{
  let newarr=arr.reduce((pre,cut,index)=>{
    let obj:Tree={
      title:cut.short,
      children:[cut]
    }
    let t=pre.some((val)=>{
      if(val.title==cut.short){
        val.children.push(cut)
        return val.title==cut.short
      }
    })
    if(!t){
      pre.push(obj)
    }
    return pre;
  },[])
  newarr.sort((a:Tree,b:Tree)=>{
    return a.title.charCodeAt(0)-b.title.charCodeAt(0)
  })
  return newarr
}